API Overview
Classes
-
obj.Object
-
dataset.Dataset
: Dataset object with easy saving and automatic versioning -
model.Model
: Intended to capture a combination of code and data the operates on an input. -
prompt.Prompt
-
prompt.StringPrompt
-
prompt.MessagesPrompt
-
eval.Evaluation
: Sets up an evaluation which includes a set of scorers and a dataset. -
eval_imperative.EvaluationLogger
: This class provides an imperative interface for logging evaluations. -
scorer.Scorer
-
annotation_spec.AnnotationSpec
-
file.File
: A class representing a file with path, mimetype, and size information. -
markdown.Markdown
: A Markdown renderable. -
monitor.Monitor
: Sets up a monitor to score incoming calls automatically. -
saved_view.SavedView
: A fluent-style class for working with SavedView objects. -
audio.Audio
: A class representing audio data in a supported format (wav or mp3).
Functions
-
api.init
: Initialize weave tracking, logging to a wandb project. -
api.publish
: Save and version a python object. -
api.ref
: Construct a Ref to a Weave object. -
api.get
: A convenience function for getting an object from a URI. -
call_context.require_current_call
: Get the Call object for the currently executing Op, within that Op. -
call_context.get_current_call
: Get the Call object for the currently executing Op, within that Op. -
api.finish
: Stops logging to weave. -
op.op
: A decorator to weave op-ify a function or method. Works for both sync and async. -
api.attributes
: Context manager for setting attributes on a call.
function init
-
project_name
**: The name of the Weights & Biases project to log to. -
settings
: Configuration for the Weave client generally. -
autopatch_settings
: Configuration for autopatch integrations, e.g. openai -
global_postprocess_inputs
: A function that will be applied to all inputs of all ops. -
global_postprocess_output
: A function that will be applied to all outputs of all ops. -
global_attributes
: A dictionary of attributes that will be applied to all traces.
function publish
-
obj
**: The object to save and version. -
name
: The name to save the object under.
function ref
location
**: A fully-qualified weave ref URI, or if weave.init() has been called, “name:version” or just “name” (“latest” will be used for version in this case).
function get
uri
**: A fully-qualified weave ref URI.
function require_current_call
get_call
method on the WeaveClient
returned from weave.init
to retrieve the Call object.
call
method. For example:
NoCurrentCallError
**: If tracking has not been initialized or this method is invoked outside an Op.
function get_current_call
function finish
function op
function attributes
class Object
Pydantic Fields:
-
name
:typing.Optional[str]
-
description
:typing.Optional[str]
-
ref
:typing.Optional[trace.refs.ObjectRef]
classmethod from_uri
classmethod handle_relocatable_object
class Dataset
Dataset object with easy saving and automatic versioning
Examples:
-
name
:typing.Optional[str]
-
description
:typing.Optional[str]
-
ref
:typing.Optional[trace.refs.ObjectRef]
-
rows
:typing.Union[trace.table.Table, trace.vals.WeaveTable]
method add_rows
rows
**: The rows to add to the dataset.
classmethod convert_to_table
classmethod from_calls
classmethod from_obj
classmethod from_pandas
method select
indices
**: An iterable of integer indices specifying which rows to select.
method to_pandas
class Model
Intended to capture a combination of code and data the operates on an input. For example it might call an LLM with a prompt to make a prediction or generate text.
When you change the attributes or the code that defines your model, these changes will be logged and the version will be updated. This ensures that you can compare the predictions across different versions of your model. Use this to iterate on prompts or to try the latest LLM and compare predictions across different settings
Examples:
-
name
:typing.Optional[str]
-
description
:typing.Optional[str]
-
ref
:typing.Optional[trace.refs.ObjectRef]
method get_infer_method
class Prompt
Pydantic Fields:
-
name
:typing.Optional[str]
-
description
:typing.Optional[str]
-
ref
:typing.Optional[trace.refs.ObjectRef]
method format
class StringPrompt
method __init__
-
name
:typing.Optional[str]
-
description
:typing.Optional[str]
-
ref
:typing.Optional[trace.refs.ObjectRef]
-
content
: “
method format
classmethod from_obj
class MessagesPrompt
method __init__
-
name
:typing.Optional[str]
-
description
:typing.Optional[str]
-
ref
:typing.Optional[trace.refs.ObjectRef]
-
messages
:list[dict]
method format
method format_message
classmethod from_obj
class Evaluation
Sets up an evaluation which includes a set of scorers and a dataset.
Calling evaluation.evaluate(model) will pass in rows from a dataset into a model matching the names of the columns of the dataset to the argument names in model.predict.
Then it will call all of the scorers and save the results in weave.
If you want to preprocess the rows from the dataset you can pass in a function to preprocess_model_input.
Examples:
-
name
:typing.Optional[str]
-
description
:typing.Optional[str]
-
ref
:typing.Optional[trace.refs.ObjectRef]
-
dataset
: “ -
scorers
:typing.Optional[list[typing.Annotated[typing.Union[trace.op.Op, flow.scorer.Scorer], BeforeValidator(func=)]]]
-
preprocess_model_input
:typing.Optional[typing.Callable[[dict], dict]]
-
trials
: “ -
evaluation_name
:typing.Union[str, typing.Callable[[trace.weave_client.Call], str], NoneType]
method evaluate
classmethod from_obj
method get_eval_results
method predict_and_score
method summarize
class EvaluationLogger
This class provides an imperative interface for logging evaluations.
An evaluation is started automatically when the first prediction is logged using the log_prediction
method, and finished when the log_summary
method is called.
Each time you log a prediction, you will get back a ScoreLogger
object. You can use this object to log scores and metadata for that specific prediction. For more information, see the ScoreLogger
class.
Example:
-
name
:str | None
-
model
:flow.model.Model | dict | str
-
dataset
:flow.dataset.Dataset | list[dict] | str
property ui_url
method finish
method log_prediction
method log_summary
class Scorer
Pydantic Fields:
-
name
:typing.Optional[str]
-
description
:typing.Optional[str]
-
ref
:typing.Optional[trace.refs.ObjectRef]
-
column_map
:typing.Optional[dict[str, str]]
method model_post_init
method score
method summarize
class AnnotationSpec
Pydantic Fields:
-
name
:typing.Optional[str]
-
description
:typing.Optional[str]
-
field_schema
:dict[str, typing.Any]
-
unique_among_creators
: “ -
op_scope
:typing.Optional[list[str]]
classmethod preprocess_field_schema
classmethod validate_field_schema
method value_is_valid
payload
**: The data to validate against the schema
bool
: True if validation succeeds, False otherwise
class File
A class representing a file with path, mimetype, and size information.
method __init__
-
path
**: Path to the file (string or pathlib.Path) -
mimetype
: Optional MIME type of the file - will be inferred from extension if not provided
property filename
Get the filename of the file. Returns:str
: The name of the file without the directory path.
method open
bool
**: True if the file was successfully opened, False otherwise.
method save
dest
**: Destination path where the file will be copied to (string or pathlib.Path) The destination path can be a file or a directory.
class Markdown
A Markdown renderable.
Args:
-
markup
(str): A string containing markdown. -
code_theme
(str, optional): Pygments theme for code blocks. Defaults to “monokai”. -
justify
(JustifyMethod, optional): Justify value for paragraphs. Defaults to None. -
style
(Union[str, Style], optional): Optional style to apply to markdown. -
hyperlinks
(bool, optional): Enable hyperlinks. Defaults toTrue
. -
inline_code_lexer
: (str, optional): Lexer to use if inline code highlighting is enabled. Defaults to None. -
inline_code_theme
: (Optional[str], optional): Pygments theme for inline code highlighting, or None for no highlighting. Defaults to None.
method __init__
class Monitor
Sets up a monitor to score incoming calls automatically.
Examples:
-
name
:typing.Optional[str]
-
description
:typing.Optional[str]
-
ref
:typing.Optional[trace.refs.ObjectRef]
-
sampling_rate
: “ -
scorers
:list[flow.scorer.Scorer]
-
op_names
:list[str]
-
query
:typing.Optional[trace_server.interface.query.Query]
-
active
: “
method activate
method deactivate
classmethod from_obj
class SavedView
A fluent-style class for working with SavedView objects.
method __init__
property entity
property label
property project
property view_type
method add_column
method add_columns
method add_filter
method add_sort
method column_index
method filter_op
method get_calls
method get_known_columns
method get_table_columns
method hide_column
method insert_column
classmethod load
method page_size
method pin_column_left
method pin_column_right
method remove_column
method remove_columns
method remove_filter
method remove_filters
method rename
method rename_column
method save
method set_columns
method show_column
method sort_by
method to_grid
method to_rich_table_str
method ui_url
method unpin_column
class Audio
A class representing audio data in a supported format (wav or mp3).
This class handles audio data storage and provides methods for loading from different sources and exporting to files.
Attributes:
-
format
**: The audio format (currently supports ‘wav’ or ‘mp3’) -
data
: The raw audio data as bytes
-
data
: The audio data (bytes or base64 encoded string) -
format
: The audio format (‘wav’ or ‘mp3’) -
validate_base64
: Whether to attempt base64 decoding of the input data
ValueError
: If audio data is empty or format is not supported
method __init__
method export
path
**: Path where the audio file should be written
classmethod from_data
-
data
**: Audio data as bytes or base64 encoded string -
format
: Audio format (‘wav’ or ‘mp3’)
Audio
: A new Audio instance
ValueError
: If format is not supported
classmethod from_path
path
**: Path to an audio file (must have .wav or .mp3 extension)
Audio
: A new Audio instance loaded from the file
ValueError
: If file doesn’t exist or has unsupported extension